import { createRouter, createWebHashHistory, RouteRecordRaw, useRoute as useRouteX } from 'vue-router'

const routes: RouteRecordRaw[] = []

const modules: any = import.meta.glob('./modules/*.ts', { eager: true })
for (const path in modules) {
  routes.push(modules[path].default)
}

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes,
  strict: false, // 是否开启严格匹配,如果开启，浏览器地址后面加个/就不会匹配

  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

router.beforeEach((to, from, next) => {
  next()
})

router.afterEach(() => {})

export default router

export function useRoute() {
  return useRouteX()
}
